<style>
    #febs-layout .layui-layout-notice {
        position: absolute;
        top: 10px;
        right: 130px;
        background: #fff;
        border-radius: 50%;
        width: 30px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    #febs-layout #layout_notice_num {
        position: absolute;
        top: 1px;
        right: 115px;
        background: red;
        color: #fff;
        font-size: 12px;
        height: 20px;
        width: 20px;
        border-radius: 50%;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
    }
</style>

<div class="layui-layout layui-layout-admin" id="febs-layout">
    <div class="layui-header layui-anim febs-anim-down" style="background:linear-gradient(to right, #EBF5FE, #ECF5FE )" id="app-header">
        <script type="text/html"
                template
                lay-done="layui.element.render('nav','febs-header')">
            <ul class="layui-nav layui-layout-left" lay-filter="febs-header">
                <li class="layui-nav-item" lay-unselect>
                    <a febs-event="flexible" title="侧边伸缩">
                        <em class="layui-icon layui-icon-shrink-right"></em>
                    </a>
                </li>
                 <span class="febs-breadcrumb"></span>
            </ul>
            <ul class="layui-layout-notice"   style="margin-right: 20px;"  id="layout_notice_dropdown_list">
                <li class="">
                    <a title="消息">
                        <em class="layui-icon layui-icon-notice"></em>
                    </a>
                </li>
            </ul>
            <div id="layout_notice_num"   style="margin-right: 20px;" ></div>
            <ul class="layui-nav layui-layout-right" lay-filter="febs-header"  >
                <li class="layui-nav-item layui-user" lay-unselect>
                    <a>
                        <img style="width: 1.9rem;margin-right:.5rem;border-radius: 50%"
                             src="{{= ctx + 'febs/images/avatar/' + currentUser.avatar }}" title="头像">
                        {{ currentUser.uname }}
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a class="layui-nav-child-href" id="user-profile">个人中心</a></dd>
                        <dd><a class="layui-nav-child-href" id="password-update">密码修改</a></dd>
                        <!--<dd><a class="layui-nav-child-href" target="_blank" href="https://github.com/wuyouzhuguli/FEBS-Shiro">项目地址</a></dd>-->
                        <hr/>
                        <dd><a class="layui-nav-child-href" data-th-href="@{logout}">退出登录</a></dd>
                    </dl>
                </li>
            </ul>
        </script>
    </div>

    <div class="febs-tabs-hidden">
        <script type="text/html" id="TPL-app-tabsmenu" template>
            {{# if(layui.conf.viewTabs){ }}
            <div class="febs-tabs-wrap">
          <span class="febs-tabs-btn febs-tabs-action febs-tabs-prev" style="background-color: #F5FAFF !important;" data-type="prev">
              <em class="layui-icon layui-icon-left"></em>
          </span>
                <span class="febs-tabs-btn febs-tabs-action febs-tabs-next"  style="background-color: #F5FAFF !important;" data-type="next">
              <em class="layui-icon layui-icon-right"></em>
          </span>
                <span class="febs-tabs-btn febs-tabs-action febs-tabs-down"  style="background-color: #F5FAFF !important;" data-type="down">
              <em class="layui-icon layui-icon-close"></em>
          </span>
                <ul class="febs-tabs-menu" style="background:linear-gradient(to right, #EBF5FE, #ECF5FE )">
                    {{# layui.each(layui.view.tab.data,function(i, item){ }}
                    <li data-type="page" class="febs-tabs-btn" style="background-color:
                    #F5FAFF!important;color: #647079" lay-url="{{item.fileurl}}">
                        <em class="febs-tabs-ball" style="background-color: #00508F !important;box-shadow: 0 0 7px #00508F;"></em>
                        {{ item.title }}<strong class="layui-icon layui-icon-close febs-tabs-close" style="color: #ABABAB"></strong>
                    </li>
                    {{# }) }}
                </ul>
            </div>
            {{# } }}
        </script>
    </div>

    <!-- 侧边菜单 -->
    <div class="layui-side" style="background: url('../../../../febs/images/ship.png') left bottom no-repeat,
    linear-gradient(to bottom, #EBF5FE, #F9FBFF);background-size: contain;" id="app-sidebar">
        <div class="layui-side-scroll">
            <div class="layui-logo" id="logo-con" style="cursor: pointer;width:100%;height: 52px;display: flex;
            align-items: center;background-color: #ECF5FE ">
                <img style=" display: inline-block;margin: 0;padding-left: 25px;
                width: 36px!important;height: 35px;" data-th-src="@{febs/images/logo1.png}">
<!--                <img style=" display: inline-block;margin: 0; width: 154px;height: 12px;" data-th-src="@{febs/images/systemName.png}">-->
                 <span style="color: #00508F;font-size: 20px;margin-left: 3px;">试验排期系统</span>
            </div>
            <script
                    type="text/html"
                    template
                    lay-api="getMenus"
                    lay-done="layui.element.render('nav','febs-sidebar');layui.febs.sidebarFocus()">
                <ul class="layui-nav layui-nav-tree" lay-filter="febs-sidebar" lay-shrink="all"  >
                    {{#
                    function __createSlidebar(data,index){
                    if(!data || data.length == 0) return '';
                    var html = '
                    <dl class="layui-nav-child" style="background-color: #F5FAFE!important">';
                        layui.each(data,function(i,child){
                        var left = index == 0 ? 50 : 50 + index * 20;
                        html += '
                        <dd><a style="padding-left:' + left + 'px;color: #596670" target="'+(child.target||'')+'"
                               lay-href="'+ (child.href||'') +'">' + child.title + '</a>';
                            if(child.childs) html += __createSlidebar(child.childs,index+1);
                            html += '</dd>';
                        });
                        html = html +'</dl>';
                    return html;
                    }
                    layui.each(d.childs, function(i,child){
                    }}
                    <li class="layui-nav-item" >
                        <a lay-href="{{child.href||''}}"  style="font-size: 14px;color: #35404F;padding: 0 28px 0 33px;
                        height: 40px;display: flex;align-items: center;margin-bottom: 10px" target="{{child.target||''}}" title="{{child.title}}">
                            <em class="layui-icon {{child.icon}}" style="color: #8799A7;
                            margin-right: 2px;"></em>
                            {{child.title}} {{# if(child.notice){ }}
                            <span class="layui-badge">{{ child.notice }}</span>{{# } }}</a>
                        {{- __createSlidebar(child.childs,0) }}
                    </li>
                    {{# }) }}
                </ul>
            </script>
        </div>
    </div>
    <!-- 主体内容 -->
    <div class="layui-body"   id="febs-body"></div>
</div>
<script data-th-inline="javascript" type="text/javascript">
    layui.use(['jquery', 'febs', 'element', 'dropdown'], function () {
        var $ = layui.jquery,
            $view = $('#febs-layout'),
            febs = layui.febs,
            dropdown = layui.dropdown;

        var element = layui.element;

        initTheme();

        $view.find('#user-avatar').attr('src', ctx + "febs/images/avatar/" + currentUser.avatar);

        $view.on('click', '.layui-logo', function () {
            febs.navigate("/index");
        });

        $view.on('click', '#password-update', function () {
            febs.modal.view('密码修改', 'password/update', {
                area: $(window).width() <= 750 ? '90%' : '500px',
                btn: ['确定'],
                yes: function () {
                    $('#user-password-update').find('#submit').trigger('click');
                }
            });
        });

        $view.on('click', '#user-profile', function () {
            febs.navigate("/user/profile");
        });

        function initTheme() {
            var theme = currentUser.theme;
            var $sidebar = $('#app-sidebar');
            if (theme === 'black') {
                $sidebar.removeClass('febs-theme-white');
            }
            if (theme === 'white') {
                $sidebar.addClass('febs-theme-white');
            }
        }

        $view.on('click', '#layout_notice_dropdown_list', function () {
            febs.modal.view('待办', 'system/notice', {
                area: ['900px', '500px'],
                // btn: ['全部已读', '关闭'],
                btn: ['关闭'],
                /*yes: function () {
                    $('#user-system-notice').find('#submit').trigger('click');
                },*/
                btn2: function () {
                    layer.closeAll();
                }
            });
        })
//待办刷新，临时注掉，后面再放开
         notice_refresh();

        function notice_refresh () {
            get_notice_num();
            setInterval(function() {
                get_notice_num();
            }, 10000);
        }

        function get_notice_num () {
            febs.get(ctx + 'notice/todoList', {}, function (result) {
                if (result.code == 200) {
                    let len = result.data.length;
                    if(len > 0){
                        $view.find('#layout_notice_num').text(len);
                    }else{
                        $view.find('#layout_notice_num').hide();
                    }

                }
            });
        }

    });
</script>
